/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = wtc_tcb_composhdr.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2015/08/27 by songbb                               */
/*******************************************************************/

#include "conntrack.h"
#include "frct_comm.h"

#include "../wtc_core.h"
#include "../wtc_comm.h"
#include "../wtc_mar.h"
#include "wtc_tcb_composhdr.h"

int wtc_tcb_composhdr_tmpostrecv(Conntrack *p_st_conn
                                , Apm_packet *p_analyze_in
                                , L7session_wtc *p_st_sess
                                , L7_wtc_packet *p_st_wtc_packet
                                , int i_recv_size
                                , int i_hint_index)
{
    unsigned int ui_opcode = 0;
    unsigned int ui_appkey = 0;
    unsigned int ui_urcode = 0;

    if (bytebuff_skip(p_st_wtc_packet->p_st_packet, 4) != FR_SUCC)
        goto error;

    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_opcode, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_appkey, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_urcode, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;

    if (bytebuff_skip(p_st_wtc_packet->p_st_packet, 16) != FR_SUCC)
        goto error;

    return FR_SUCC;
error:
    return FR_FAIL;
}

int wtc_tcb_composhdr_tmpostrecv_fad(char *p_payload
                                    , unsigned int ui_payload_len
                                    , unsigned int *p_ui_offset
                                    , int *p_i_direction
                                    , int i_recv_size
                                    , int i_hint_index)
{
    unsigned int ui_opcode = 0;
    if (wtc_skip(p_payload, ui_payload_len, p_ui_offset, 4) != FR_SUCC)
        goto error;
    if (wtc_get_int(p_payload, ui_payload_len, p_ui_offset, &ui_opcode) != FR_SUCC)
        goto error;
    *p_i_direction = wtc_analyze_direction_by_opcode(ui_opcode);
    if (*p_i_direction != FR_DIRECT_UNKNOWN)
        return FR_SUCC;
    if (wtc_skip(p_payload, ui_payload_len, p_ui_offset, 24) != FR_SUCC)
        goto error;

    return FR_SUCC;
error:
    return FR_FAIL;
}
